package com.lgt_enterprise_android.view.pages;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lgt_enterprise_android.R;
import com.lgt_enterprise_android.base.BaseActivity;
import com.lgt_enterprise_android.view.widgets.weekcalendar.WeekCalendarView;
import com.util.AppUtil;

public class TestCanlederActivity extends BaseActivity {

    private LinearLayout viewContent;
    private FrameLayout frameLayout;

    private WeekCalendarView weekCalendarView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_canleder);
        weekCalendarView=(WeekCalendarView)findViewById(R.id.weekCalendar);

        weekCalendarView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                log("11---"+weekCalendarView.getSelectedDate().toString());
            }
        });

        initCalender();
        drawData(2,8);

        drawData(9,18);

        drawData(23,24);
    }

    private void initCalender(){
        viewContent = (LinearLayout) findViewById(R.id.arrange);
        frameLayout=(FrameLayout)findViewById(R.id.frame);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.topMargin = (int)(AppUtil.getdensityDpi(mContext) * 30);

        for (int i = 1; i < 25; i++) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.item_arrange, null);
            ((TextView)view.findViewById(R.id.txt_time)).setText(i+":00");
            view.setTag(i);
            if(i==1){
                viewContent.addView(view);
            }else{
                viewContent.addView(view, lp);
            }
        }
    }

    private void drawData(final int startTime,final int endTime){
        getWindow().getDecorView().post(new Runnable() {
            @Override
            public void run() {
                View viewStart= viewContent.findViewWithTag(startTime);
                View viewEnd= viewContent.findViewWithTag(endTime);
                FrameLayout.LayoutParams lp=new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,viewEnd.getTop()-viewStart.getTop());
                lp.topMargin=(int)(viewStart.getTop()+AppUtil.getdensityDpi(mContext) * 15);
                lp.leftMargin =(int)( AppUtil.getdensityDpi(mContext) * 48);
                lp.rightMargin =(int)( AppUtil.getdensityDpi(mContext) * 5);

                View viewCon=new View(mContext);
                viewCon.setBackgroundColor(mContext.getResources().getColor(R.color.colorAccent));
                viewCon.setAlpha(0.6f);

                frameLayout.addView(viewCon,lp);


            }
        });

    }
}
